#include "systemtrayicon.h"

SystemTrayIcon::SystemTrayIcon(QObject *parent) :
    QSystemTrayIcon(parent),
    trayiconMenu(new QMenu),
    minimizeAction(new QAction(this)),
    maximizeAction(new QAction(this)),
    restoreAction(new QAction(this)),
    quitAction(new QAction(this))
{
    //创建QIcon对象，参数是图标资源，值为项目的资源文件中图标的地址
    QIcon icon(":/御坂美琴.ico");
    //托盘设置图标
    this->setIcon(icon);//设置图标
    this->setToolTip("wallpaper");//设置提示语
    this->show();

    //动作添加信息
    minimizeAction->setText(tr("Min"));
    maximizeAction->setText(tr("Max"));
    restoreAction->setText(tr("Normal"));
    quitAction->setText(tr("Exit"));

    //托盘菜单添加动作
    trayiconMenu->addAction( minimizeAction);
    trayiconMenu->addAction( maximizeAction);
    trayiconMenu->addAction( restoreAction);
    trayiconMenu->addAction( quitAction);

    //托盘添加菜单
    this->setContextMenu(trayiconMenu);

    //Quit On Last Window Closed退出在最后窗口关闭点击关闭时程序不关闭
    QApplication::setQuitOnLastWindowClosed(false);

    connect( minimizeAction, SIGNAL(triggered()), this, SIGNAL(showMinimized()));//若是触发了最小化就隐藏窗口
    connect( maximizeAction, SIGNAL(triggered()), this, SIGNAL(showMaximized()));//若触发了最大化就最大化窗口
    connect( restoreAction, SIGNAL(triggered()), this, SIGNAL(showNormal()));//若触发了还原就正常显示
    connect( quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));//若触发了退出就退出程序
}

SystemTrayIcon::~SystemTrayIcon()
{
    delete trayiconMenu;
    delete minimizeAction;
    delete maximizeAction;
    delete restoreAction;
    delete quitAction;
}
